package com.wisdytech.common.thrift.service.impl;


import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.wisdytech.common.thrift.service.ThriftClient;


@Service("ThriftClient")
public class ThriftClientImpl implements ThriftClient {
	
	private static Logger logger =LoggerFactory.getLogger(ThriftClientImpl.class);
	
	@Value("${thrift.dcs.ip}")
	private String ip;
	@Value("${thrift.dcs.port}")
	private int port;
	
	public ThriftClientImpl(){}

	@Override
	public TFramedTransport getTransprot() {
		
		TSocket tsocket=new TSocket(ip,port);
		tsocket.setConnectTimeout(2000);
		tsocket.setTimeout(2000);
		 TFramedTransport tTransport1 = new TFramedTransport(tsocket);
	        try {
	        	tTransport1.open();
	            /*TProtocol protocol=new TBinaryProtocol(tTransport);
	            LinkDCSService.Client client =new LinkDCSService.Client(protocol);*/
	           return tTransport1;
	            
	            
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException(e);
	        }
	        
	        
	}

	@Override
	public void close(TTransport transprot) {
		if(null!=transprot){
			transprot.close();
		}

	}

}
